package com.wms.function.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wms.common.annotation.Log;
import com.wms.common.core.controller.BaseController;
import com.wms.common.core.domain.AjaxResult;
import com.wms.common.enums.BusinessType;
import com.wms.function.domain.TbGoodsOwner;
import com.wms.function.service.ITbGoodsOwnerService;
import com.wms.common.utils.poi.ExcelUtil;
import com.wms.common.core.page.TableDataInfo;

/**
 * 货主Controller
 *
 * @author znl
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/function/goodsOwner")
@Api(tags = "货主的接口")
public class TbGoodsOwnerController extends BaseController {
    @Autowired
    private ITbGoodsOwnerService tbGoodsOwnerService;

/**
 * 查询货主列表
 */
@ApiOperation("查询货主列表")
@PreAuthorize("@ss.hasPermi('function:goodsOwner:list')")
@GetMapping("/list")
    public TableDataInfo list(TbGoodsOwner tbGoodsOwner) {
        startPage();
        List<TbGoodsOwner> list = tbGoodsOwnerService.selectTbGoodsOwnerList(tbGoodsOwner);
        return getDataTable(list);
    }

    /**
     * 导出货主列表
     */
    @ApiOperation("导出货主列表")
    @PreAuthorize("@ss.hasPermi('function:goodsOwner:export')")
    @Log(title = "货主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbGoodsOwner tbGoodsOwner) {
        List<TbGoodsOwner> list = tbGoodsOwnerService.selectTbGoodsOwnerList(tbGoodsOwner);
        ExcelUtil<TbGoodsOwner> util = new ExcelUtil<TbGoodsOwner>(TbGoodsOwner. class);
        util.exportExcel(response, list, "货主数据");
    }

    /**
     * 获取货主详细信息
     */
    @ApiOperation("获取货主详细信息")
    @PreAuthorize("@ss.hasPermi('function:goodsOwner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "货主ID", required = true)
                              @PathVariable("id") Long id) {
        return success(tbGoodsOwnerService.selectTbGoodsOwnerById(id));
    }

    /**
     * 新增货主
     */
    @ApiOperation("新增货主")
    @PreAuthorize("@ss.hasPermi('function:goodsOwner:add')")
    @Log(title = "货主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "货主实体")
                          @RequestBody TbGoodsOwner tbGoodsOwner) {
        return toAjax(tbGoodsOwnerService.insertTbGoodsOwner(tbGoodsOwner));
    }

    /**
     * 修改货主
     */
    @ApiOperation("修改货主")
    @PreAuthorize("@ss.hasPermi('function:goodsOwner:edit')")
    @Log(title = "货主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "货主实体")
                           @RequestBody TbGoodsOwner tbGoodsOwner) {
        return toAjax(tbGoodsOwnerService.updateTbGoodsOwner(tbGoodsOwner));
    }

    /**
     * 删除货主
     */
    @ApiOperation("删除货主")
    @PreAuthorize("@ss.hasPermi('function:goodsOwner:remove')")
    @Log(title = "货主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbGoodsOwnerService.deleteTbGoodsOwnerByIds(ids));
    }
}
